
;.nolist
#include <avr/io.h>	// Include device specific definitions.
;.list

.global initUSART
.func initUSART
initUSART:
	ldi r19, 0
	ldi r18, 103 ;9600bps
	out _SFR_IO_ADDR(UBRRH), r19 ; Set baud rate
	out _SFR_IO_ADDR(UBRRL), r18
	ldi r18, (1<<RXEN)|(1<<TXEN) ; Enable Receiver and Transmitter
	out _SFR_IO_ADDR(UCSRB),r18
	; Set frame format: 8data, 1stop bit
	ldi r18, (1<<URSEL)|(3<<UCSZ0)
	out _SFR_IO_ADDR(UCSRC),r18
	ret
.endfunc

.global transmitUSART
.func transmitUSART
transmitUSART:
	sbis _SFR_IO_ADDR(UCSRA),UDRE ; Wait for empty transmit buffer
	rjmp transmitUSART
	out _SFR_IO_ADDR(UDR), r24
.endfunc
